<?php
declare (strict_types=1);

namespace app\model;

use think\facade\Route;
use think\Model;

/**
 * @mixin Model
 */
class Attach extends Model
{
    public static function onAfterRead($attach)
    {
        if (env('redirect_upyun')) {
            $attach['url'] = env('UPYUN_DOMAIN') . '/' . $attach['path'];
            $attach['url_small'] = $attach['url'] . "!small";
            return $attach;
        }
        return $attach['url'] = (string)Route::buildUrl('attach/read', ['id' => $attach['key']])->domain(true);
    }
}
